/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.uc.manager.impl;

import java.util.Collection;
import java.util.List;

import com.xy.biz.uc.dao.PositionDao;
import com.xy.biz.uc.domain.bo.PositionBO;
import com.xy.biz.uc.domain.converter.PositionConverter;
import com.xy.biz.uc.domain.query.PositionQuery;
import com.xy.biz.uc.manager.PositionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 *
 *
 * @author zgy
 * @date 2021-9-23
 */
@Service
public class PositionManagerImpl implements PositionManager {

    @Autowired
    private PositionDao positionDao;

    @Override
    public int savePosition(PositionBO positionBO) {
        PositionBO positionByUserId = getPositionByUserId(positionBO.getUserId());
        int result;
        if (positionByUserId == null) {
            result = positionDao.savePosition(PositionConverter.toPO(positionBO));
        } else {
            positionBO.setPositionId(positionByUserId.getPositionId());
            result = updatePosition(positionBO);
        }
        return result;
    }

    @Override
    public int saveAllPosition(Collection<PositionBO> collection) {
        return positionDao.saveAllPosition(PositionConverter.toPO(collection));
    }

    @Override
    public int updatePosition(PositionBO positionBO) {
        return positionDao.updatePosition(PositionConverter.toPO(positionBO));
    }

    @Override
    public int deletePosition(Long positionId) {
        return positionDao.deletePosition(positionId);
    }

    @Override
    public PositionBO getPosition(Long positionId) {
        return PositionConverter.fromPO(positionDao.getPosition(positionId));
    }

    /**
     * 根据UserId查找一个
     *
     * @param userId
     * @return
     */
    @Override
    public PositionBO getPositionByUserId(Long userId) {
        return PositionConverter.fromPO(positionDao.getPositionByUserId(userId));
    }

    @Override
    public List<PositionBO> listPositionByUserId(Collection<Long> collection) {
        return PositionConverter.fromPO(positionDao.listPositionByUserId(collection));
    }

    @Override
    public List<PositionBO> listPositionById(Collection<Long> collection) {
        return PositionConverter.fromPO(positionDao.listPositionById(collection));
    }

    @Override
    public List<PositionBO> listPosition(PositionQuery query) {
        return PositionConverter.fromPO(positionDao.listPosition(query));
    }

    @Override
    public int countPosition(PositionQuery query) {
        return positionDao.countPosition(query);
    }

}
